package cn.paper;

import cn.print.Paper;

public class TestPaper implements Paper {
    private  int posX =0;
    private  int posY =0;
    private  int  posP =1;
    private int charPerLine =15;
    private int LinePerPage = 6;
    private  String content;


    @Override
    public void putInChar(char c) {
        content += c;
        ++posX;
        if (posX == charPerLine){
            content += Paper.newLine;
            posX = 0;
            ++ posY;
        }
        if (posY ==LinePerPage){
            content +="第"+ posP +"页";
            content += Paper.newLine +Paper.newLine;
            posP  = 0;
            ++ posP;
        }
    }

    @Override
    public String getContent() {
        String ct = this.content;
        if (!(posP == 0 && posX == 0)){
            int count =LinePerPage -posY;
            for (int i =0 ;i<count; i++){
                ct += Paper.newLine;
            }
            ct += "第"+posP+"页";
        }
        return ct;
    }

    public void setCharPerLine(int charPerLine) {
        this.charPerLine = charPerLine;
    }

    public void setLinePerPage(int linePerPage) {
        LinePerPage = linePerPage;
    }
}
